package com.huobao.yunying.adapters;

import java.util.List;

import com.huobao.yunying.entity.Detail_images;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.yunying.utils.ImageUtils.OnImageLoadListener;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.utils.ScreenUtil;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;

public class Detail_ImageAdapter_New extends BaseAdapter{

	private LayoutInflater inflater;
	private Context context;
	private List<Detail_images> list;
	private RelativeLayout layout;
	public Detail_ImageAdapter_New(Context context, List<Detail_images> list, RelativeLayout layout){
		inflater = LayoutInflater.from(context);
		this.context = context;
		this.layout = layout;
		this.list = list;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return Integer.MAX_VALUE;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		if(list.size() == 0)return null;
		return list.get(position%list.size());
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = inflater.inflate(R.layout.image_item, null);
		}
		if(list.size() == 0)return convertView;
		ImageView imgView = (ImageView) convertView.findViewById(R.id.imgView);
		ImageUtils.loadimg(imgView, list.get(position%list.size()).image_url, new OnImageLoadListener() {

			@Override
			public void onLoadSuccess(Drawable drawable) {
				int newHight = ScreenUtil.getInstant().getDisWidth(context) * drawable.getIntrinsicHeight()
						/ drawable.getIntrinsicWidth();
				LayoutParams params = (LayoutParams) layout.getLayoutParams();
				params.width = ScreenUtil.getInstant().getDisWidth(context);
				params.height = newHight;
				layout.setLayoutParams(params);
			}
		});
		return convertView;
	}

}
